﻿using System;
using System.IO;
using System.Linq;
using System.Web.Mvc;
using BLL;
using Model;
using Web.Helper;

namespace Web.Areas.Manager.Controllers
{


    [UserAuthorize]
    public class ELMAH_ErrorController : Controller
    {
        ELMAH_Error_BLL _ELMAH_Error_BLL = new ELMAH_Error_BLL();

        public virtual ActionResult Index(int? pageIndex, string keyword)
        {
            var model = _ELMAH_Error_BLL.Get();
            if (!string.IsNullOrEmpty(keyword))
            {
                model = model.Where(a => a.Host.Contains(keyword) || a.Message.Contains(keyword) || a.Source.Contains(keyword) || a.Type.Contains(keyword) || a.User.Contains(keyword));
            }
            return View(model.ToPagedList(pageIndex));
        }

        [HttpDelete]
        public virtual ActionResult Delete(Guid? Id)
        {
            if (Id.HasValue)
            {
                _ELMAH_Error_BLL.Delete(Id.Value);
            }
            else
            {
                _ELMAH_Error_BLL.DeleteAll();
            }
            return RedirectToAction("Index", MyrouteValues.Get());
        }
    }
}